#include <bits/stdc++.h>
using namespace std;
#define int long long

const int p = 1e9+7;
int n, k, pw2[1024];
pair<int, int> dp[1024][1024][2][2];
char d[1024], l[1024], r[1024], s[1024];

pair<int, int> dfs(int i, int ks, int flg, int lim) {
	if (ks < 0) return {0, 0};
	if (i == n + 1) {
		return {ks == 0, 0};
	}
	if (dp[i][ks][flg][lim].first != -1) return dp[i][ks][flg][lim];
	int ans1 = 0, ans2 = 0;
	for (int dig = 0; dig <= max((int)s[i] - '0', lim); ++dig) {
		// 当前没有修改方向
		if (dig == (d[i] ^ flg)) {
			auto t = dfs(i + 1, ks, flg, lim || (dig != s[i] - '0'));
			(ans1 += t.first ) %= p;
			(ans2 += t.first * pw2[n - i] * dig +t.second) %= p;
		} else if (i == 2) {
			auto t = dfs(i + 1, ks, flg ^ 1, lim || (dig != s[i] - '0'));
			(ans1 += t.first ) %= p;
			(ans2 += t.first * pw2[n - i] * dig +t.second) %= p;
		}
		// 修改一次方向
		if (dig != (d[i] ^ flg)) {
			auto t = dfs(i + 1, ks - 1, flg ^ 1, lim || (dig != s[i] - '0'));
			(ans1 += t.first ) %= p;
			(ans2 += t.first * pw2[n - i] * dig +t.second) %= p;
		} else if (i == 2) {
			auto t = dfs(i + 1, ks - 1, flg, lim || (dig != s[i] - '0'));
			(ans1 += t.first ) %= p;
			(ans2 += t.first * pw2[n - i] * dig +t.second) %= p;
		}
	}
	return dp[i][ks][flg][lim] = {ans1, ans2};
}

int solve(char *t) {
	for (int i = 1; i <= n; ++i) s[i] = t[i];
	memset(dp, 255, sizeof(dp));
	pair<int, int> tp = dfs(2, k, 0, 0);
	return (tp.second + tp.first * pw2[n - 1]) % p;
}

signed main() {
	freopen("lost.in", "r", stdin); freopen("lost.out", "w", stdout);
	pw2[0] = 1;
	for (int i = 1; i <= 1014; ++i) pw2[i] = pw2[i - 1] * 2 % p;
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	if (n == 0) {
		cout << "0\n";
		return 0;
	}
	if (n != 1) cin >> (d + 2);
	cin >> (l + 1) >> (r + 1);
	for (int i = 2; i <= n; ++i) {
		if (d[i] == 'L') d[i] = 0;
		else d[i] = 1;
	}
	for (int i = n; i >= 1; --i) {
		if (l[i] == '0') {
			l[i] = '1';
		} else {
			l[i] = '0';
			break;
		}
	}
	int ans = solve(r);
	if (l[1] == '1') ans -= solve(l);
	cout << (ans % p + p) % p << "\n";
	return 0;
}
